package com.houdoudou.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateTimeFunction {

	public static String getMyDateTime(int minuteOffset){
		String dateTime="";
		Date  now = new Date();
		System.out.println("current time="+ now);
		now.setMinutes(now.getMinutes()+minuteOffset);	
		System.out.println("current time after offset ="+ now);
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		dateTime=dateFormat.format( now ); 
	//	System.out.println("current time after offset in myfortmat ="+ dateTime);
		return dateTime;
	}
	
	public static Date addDay(Date date, int days){		
		Calendar ca= Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.DATE, days);	
		return ca.getTime();
	}
	public static Date addMonth(Date date, int monthes){		
		Calendar ca= Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.MONTH,  monthes);	
		return ca.getTime();
	}
	
	public static Date addHour(Date date, int hours){		
		Calendar ca= Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.HOUR_OF_DAY, hours);	
		return ca.getTime();
	}
	public static String myDateFormat(Date date){
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		return dateFormat.format( date );
	}
	
	public static Date parseMyDateFormat(String dateStr) throws ParseException{
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		return dateFormat.parse(dateStr);
	
	}
	
	public static Long myDateTimeValue(Date date){
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		return Long.parseLong(dateFormat.format( date ));
	}
	
	public static Long myDateTimeValue(String dateStr){
		return Long.parseLong(dateStr);
	}
	
}
